<template>
  <div class="home">
    <el-container>
      <el-header>
        <h2>后台管理系统</h2>
        <p>
          <el-button @click="logout">退出</el-button>
        </p>
      </el-header>
      <el-container>
        <el-aside :width="flag?'64px':'200px'">
          <div class="top-bar" @click="flag=!flag">|||</div>
          <el-menu
            default-active="2"
            class="el-menu-vertical-demo"
            :unique-opened="true"
            router
            :collapse-transition="false"
            :collapse="flag"
            active-text-color="pink"
          >
            <!-- 一级菜单 -->
            <el-submenu :index="item.id+''" v-for="item in AsideList" :key="item.id">
              <template slot="title">
                <i class="el-icon-location"></i>
                <span>{{item.authName}}</span>
              </template>
              <el-menu-item-group>
                <!-- 二级菜单 -->
                <el-menu-item
                  :index="'/home/'+it.path+''"
                  v-for="it in item.children"
                  :key="it.id"
                >{{it.authName}}</el-menu-item>
              </el-menu-item-group>
            </el-submenu>
          </el-menu>
        </el-aside>
        <el-main>
          <router-view></router-view>
        </el-main>
      </el-container>
    </el-container>
  </div>
</template>

<script>
export default {
  name: "Home",
  components: {},
  data() {
    return {
      AsideList: [],
      // 伸缩侧边栏
      flag: false
    };
  },
  methods: {
    //点击退出,清空本地存储
    logout() {
      sessionStorage.clear();
      this.$message({
        message: "请先登录",
        type: "success"
      });
      this.$router.push("/login");
    },

    // 侧边栏数据
    async geiAside() {
      let { data: res } = await this.$http.get("/menus");
      this.AsideList = res.data;
    }
  },
  mounted() {
    this.geiAside();
  }
};
</script>
<style lang="scss" scope>
.el-container,
.home {
  width: 100%;
  height: 100%;
}
.el-header {
  background-color: #b3c0d1;
  color: #333;
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.el-aside {
  background-color: #d3dce6;
  color: #333;
}

.el-main {
  background-color: #e9eef3;
  color: #333;
}
.top-bar {
  background-color: #4a5064;
  color: #fff;
  font-size: 12px;
  text-align: center;
  line-height: 22px;
  cursor: pointer;
  letter-spacing: 0.12em;
}
</style>
